package com.ease.model.type;

import com.ease.common.enums.EnumUtil;
import com.ease.common.enums.TextualEnum;

/**
 * http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_1037.htm
 * 
 * @author nathanleewei
 * 
 */
public enum DatabaseConstraintType implements TextualEnum {

	C("CheckConstraintOnATable"), //
	P("PrimaryKey"), //
	U("UniqueKey"), //
	V("withCheckOptionOnAView"), //
	O("withReadOnlyOnAView"), //
	R("ReferentialIntegrity"); //

	private String text;

	private DatabaseConstraintType(String text) {
		this.text = text;
	}

	public static DatabaseConstraintType get(String name) {
		return EnumUtil.get(DatabaseConstraintType.class, name);
	}

	public static DatabaseConstraintType getByText(String text) {
		for (Object o : DatabaseConstraintType.class.getEnumConstants()) {
			DatabaseConstraintType e = (DatabaseConstraintType) o;
			if (e.getText().equals(text)) {
				return e;
			}
		}
		return null;
	}

	public String getName() {
		return name();
	}

	/**
	 * @return the text
	 */
	public String getText() {
		return text;
	}
}
